package com.blockmeta.bbs.businesslibrary.umeng;

import android.content.Context;
import android.graphics.Bitmap;

import com.blockmeta.bbs.businesslibrary.umeng.dialog.BlockMessageShareData;
import com.umeng.socialize.UMShareListener;

/**
 * @author AirThor
 * @date 2020/3/23.
 * 分享路由器，这里进行参数组装，根据分享类型分发给特定的分享方法
 */
public class ShareRouter {
    private ShareRouter(Builder builder) {
        init(builder);
    }

    /** 上下文对象 */
    private Context mContext;
    /**由于各个分享页面具有差异性，所以通过{@link ShareType}来标识分享类型*/
    private ShareType mShareType;
    /**用于描述该分享具体由哪个页面分享的字段*/
    private TypeDescribe mTypeDescribe;
    /** 友盟回调 */
    private UMShareListener mUMShareListener;
    /** 标题 */
    private String mTitle;
    /** 缩略图 */
    private String mThumb;
    /** 描述 */
    private String mDesc;
    /** 分享内容的网页地址 */
    private String mUrl;
    /** 需要展示的图片*/
    private Bitmap mDisplayBitmap;
    /** 自定义类型 如K线 F10分享等，直接传递json字符串*/
    private String mCustomShareJson;
    /** 需要展示的图片数组，适用于多个图片*/
    private Bitmap[] mDisplayBitmaps;
    /** 快讯特有数据 */
    private BlockMessageShareData mBlockMessageShareData;
    /** 分享到哪个平台的监听，供调用页面做一些监听处理，例如分享埋点*/
    private OnShareClickListener mOnShareClickListener;

    /**
     * 建造者 将参数对调用者的影响屏蔽
     */
    public static class Builder{
        private Context mContext;
        private ShareType mShareType;
        private TypeDescribe mTypeDescribe;
        private UMShareListener mUMShareListener;
        private String mTitle;
        private String mThumb;
        private String mDescribe;
        private String mUrl;
        private Bitmap mDisplayBitmap;
        private String mCustomShareJson;
        private Bitmap[] mDisplayBitmaps;
        private BlockMessageShareData mBlockMessageShareData;
        private OnShareClickListener mOnShareClickListener;

        public Builder context(Context context) {
            mContext = context;
            return this;
        }

        public Builder shareType(ShareType shareType) {
            mShareType = shareType;
            return this;
        }

        public Builder typeDescribe(TypeDescribe typeDescribe) {
            mTypeDescribe = typeDescribe;
            return this;
        }

        public Builder umShareListener(UMShareListener umShareListener) {
            mUMShareListener = umShareListener;
            return this;
        }

        public Builder title(String title) {
            mTitle = title;
            return this;
        }

        public Builder thumb(String thumb) {
            mThumb = thumb;
            return this;
        }

        public Builder describe(String describe) {
            mDescribe = describe;
            return this;
        }

        public Builder url(String url) {
            mUrl = url;
            return this;
        }

        public Builder displayBitmap(Bitmap displayBitmap) {
            mDisplayBitmap = displayBitmap;
            return this;
        }

        public Builder customShareJson(String customShareJson) {
            mCustomShareJson = customShareJson;
            return this;
        }

        public Builder displayBitmaps(Bitmap[] displayBitmaps) {
            mDisplayBitmaps = displayBitmaps;
            return this;
        }

        public Builder blockMessageShareData(BlockMessageShareData blockMessageShareData) {
            mBlockMessageShareData = blockMessageShareData;
            return this;
        }

        public ShareRouter build(){
            return new ShareRouter(this);
        }

        public Builder onShareClickListener(OnShareClickListener onShareClickListener) {
            mOnShareClickListener = onShareClickListener;
            return this;
        }
    }

    private void init(Builder builder) {
        mContext = builder.mContext;
        mShareType = builder.mShareType;
        mTypeDescribe = builder.mTypeDescribe;
        if (mShareType==null) {
            throw new NullPointerException("ShareType must not be null");
        }
        mUMShareListener = builder.mUMShareListener;
        mTitle = builder.mTitle;
        mThumb = builder.mThumb;
        mDesc = builder.mDescribe;
        mUrl = builder.mUrl;
        mDisplayBitmap = builder.mDisplayBitmap;
        mCustomShareJson = builder.mCustomShareJson;
        mDisplayBitmaps = builder.mDisplayBitmaps;
        mBlockMessageShareData = builder.mBlockMessageShareData;
        mOnShareClickListener = builder.mOnShareClickListener;
    }

    public Context getContext() {
        return mContext;
    }

    public ShareType getShareType() {
        return mShareType;
    }

    public TypeDescribe getTypeDescribe() {
        return mTypeDescribe;
    }

    public UMShareListener getUMShareListener() {
        return mUMShareListener;
    }

    public String getTitle() {
        return mTitle;
    }

    public String getThumb() {
        return mThumb;
    }

    public String getDesc() {
        return mDesc;
    }

    public String getUrl() {
        return mUrl;
    }

    public Bitmap getDisplayBitmap() {
        return mDisplayBitmap;
    }

    public String getCustomShareJson() {
        return mCustomShareJson;
    }

    public Bitmap[] getDisplayBitmaps() {
        return mDisplayBitmaps;
    }

    public BlockMessageShareData getBlockMessageShareData() {
        return mBlockMessageShareData;
    }

    public OnShareClickListener getOnShareClickListener() {
        return mOnShareClickListener;
    }

    /**
     * 展示分享页面
     */
    public void show(){
        DistributionShare.distribution(mShareType,mContext,this);
    }
}
